package com.zx._07_数据库.测试数据;

import com.zx._07_数据库.jdbc.JDBC;
import java.sql.Connection;
import java.sql.PreparedStatement;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SaveCourse {

    public static void save() {
        log.info("save SaveCourse begin");
        String sql = "INSERT INTO t_course(id, name) VALUES(?, ?)";

        Connection connection = JDBC.getConnection();
        PreparedStatement ps = null;
        try {
            ps = connection.prepareStatement(sql);
            for (int i = 0; i < Config.COURSE_NAMES.length; i++) {
                ps.setInt(1, i + 1);
                ps.setString(2, Config.COURSE_NAMES[i]);
                ps.addBatch();
            }
            ps.executeBatch();
            log.info("save SaveCourse finsh");
        } catch (Exception e) {
            log.error("save SaveCourse error", e);
        } finally {
            JDBC.release(connection, ps, null);
        }
    }
}
